import sys
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QMainWindow
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QDockWidget, QTextEdit

class DockWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("停靠窗口示例")
        self.resize(600, 400)
        
        # 中央部件
        text_edit = QTextEdit()
        self.setCentralWidget(text_edit)
        
        # 创建停靠窗口
        dock = QDockWidget("工具面板", self)
        dock.setAllowedAreas(
            Qt.DockWidgetArea.LeftDockWidgetArea | 
            Qt.DockWidgetArea.RightDockWidgetArea
        )
        
        # 停靠窗口的内容
        dock_content = QWidget()
        dock_layout = QVBoxLayout()
        
        for i in range(5):
            button = QPushButton(f"工具 {i+1}")
            dock_layout.addWidget(button)
        
        dock_content.setLayout(dock_layout)
        dock.setWidget(dock_content)
        
        # 添加停靠窗口到主窗口
        self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, dock)

# 使用停靠窗口
app = QApplication(sys.argv)
window = DockWindow()
window.show()
sys.exit(app.exec())
